import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';

@Component({
  selector: 'bz-table-selection',
  template: '',
  exportAs: 'bzTableSelection'
})
export class TableSelectionComponent implements OnChanges {


  /** 选择模式 */
  @Input() mode: 'multiple' | 'none' | 'single' = 'none';
  /** 前端分页时选择所有，后端分页时选择当前页 */
  @Input() selectAllMode: 'allPages' | 'page' = 'allPages';
  /** 选择动作，{always：只能通过选择框选中，onClick：可通过单击行选中，none：不显示选择列} */
  @Input() showCheckBoxesMode: 'always' | 'none' | 'onClick' = 'always';

  /** 自定义选择操作，复选框以 checked 确定选中状态 */
  @Input() bzSelections: Array<{ text: string, onSelect: any }>;

  // @Input() allowSelectAll = true;
  // @Input() deferred = false;
  @Output() propertyChanges = new EventEmitter();

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.mode && changes.mode.currentValue) {
      this.propertyChanges.emit({
        type: 'mode',
        value: changes.mode.currentValue
      });
    }
    if (changes.selectAllMode && changes.selectAllMode.currentValue) {
      this.propertyChanges.emit({
        type: 'selectAllMode',
        value: changes.selectAllMode.currentValue
      });
    }
    if (changes.showCheckBoxesMode && changes.showCheckBoxesMode.currentValue) {
      this.propertyChanges.emit({
        type: 'showCheckBoxesMode',
        value: changes.showCheckBoxesMode.currentValue
      });
    }
  }
}
